package it.webrules.deploymanager.core.st.scm;

import it.webrules.deploymanager.core.config.ConfigurationService;
import it.webrules.deploymanager.core.st.scm.svn.SvnConnector;
import it.webrules.xsd.dmc.config.v1.ScmSystem;
import it.webrules.xsd.dmc.config.v1.StaticConfig;
import it.webrules.xsd.dmc.config.v1.StaticConfig.Scm;

public class SCMService {

	private SCMConnector scmConnector;
	private StaticConfig staticConfig;

	public SCMService(ConfigurationService configurationService) throws SCMException {

		staticConfig = configurationService.getStaticConfig();

		Scm scm = staticConfig.getScm();
		ScmSystem scmSystem = scm.getType();

		try {

			switch (scmSystem) {
			case SVN:
				scmConnector = new SvnConnector(staticConfig);
				break;
			default:
				throw new SCMException("Only SVN as scm is supported!");
			}

		} catch (Exception e) {
			throw new SCMException("Can't create scm connection.", e);
		}

	}

	public SCMConnector getScmConnector() {
		return scmConnector;
	}

	public StaticHookManager getStaticHookManager() {
		return new StaticHookManager(staticConfig);
	}
}
